/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_DIRECTOR_IMPL__
#define __CC_PYTHON_IMPORT_O_DIRECTOR_IMPL__

#include "python_object_director.h"
#include "python_object_nodeobjects.h"

NS_CCPY_BEGIN

	PYCLASS_INIT_F(CPyDirector, "sharedDirector", "Python sharedDirector Object");

	PYCLASS_BEGIN_METHOD_DEF(CPyDirector)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setViewport			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, convertToGL			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, convertToUI			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, runWithScene			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, pushScene			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, popScene				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, popToRootScene		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, replaceScene			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, drawScene			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, purgeCachedData		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, end					, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, pause				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, resume				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setGLDefaultValues	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setAlphaBlending		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setDepthTest			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getRunningScene		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getSecondsPerFrame	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, isPaused				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getTotalFrames		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, isSendCleanupToScene	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getWinSize			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getWinSizeInPixels	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getVisibleSize		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getVisibleOrigin		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getZEye				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getDeltaTime			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getAnimationInterval	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setAnimationInterval	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, isDisplayStats		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setDisplayStats		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getOpenGLView		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setOpenGLView		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, isNextDeltaTimeZero	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setNextDeltaTimeZero	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getNotificationNode	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setNotificationNode	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getDelegate			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setDelegate			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getProjection		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setProjection		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getContentScaleFactor, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setContentScaleFactor, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getScheduler			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setScheduler			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getActionManager		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setActionManager		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getTouchDispatcher	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setTouchDispatcher	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getKeypadDispatcher	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setKeypadDispatcher	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, getAccelerometer		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, setAccelerometer		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, addStandardDelegate	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, addTargetedDelegate	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyDirector, removeDelegate		, METH_STATIC|METH_VARARGS)
	PYCLASS_END_METHOD_DEF(CPyDirector)

	PYCLASS_BEGIN_GETSET_DEF(CPyDirector)
	PYCLASS_END_GETSET_DEF(CPyDirector)

	PYCLASS_IMP_INTERFACE(CPyDirector)

	CPyDirector::CPyDirector()
	{
	}
	
	PYCLASS_METHOD_IMPL(CPyDirector, runWithScene)
	{
		PyObject* scene = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&scene) )
		{
			Py_RETURN_NONE;
		}
		if(!scene)
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(scene, CPyClassBase::GetTypeObject<CPyScene>()))
			Py_RETURN_NONE;
		CPyScene *pyScene = (CPyScene *)scene;
		cocos2d::CCScene *pScene = dynamic_cast<cocos2d::CCScene *>(pyScene->getCCObject());
		if(pScene)
			cocos2d::CCDirector::sharedDirector()->runWithScene(pScene);
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPyDirector, setViewport)
	{
		cocos2d::CCDirector::sharedDirector()->setViewport();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, convertToGL)
	{
		PyObject* pt = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&pt) )
			Py_RETURN_NONE;
		if(!pt || !PyObject_TypeCheck(pt, CPyClassBase::GetTypeObject<CPyPoint>()))
			Py_RETURN_NONE;
		CPyPoint *point = (CPyPoint *)pt;
		cocos2d::CCPoint dst = cocos2d::CCDirector::sharedDirector()->convertToGL(point->getCCObject());
		return (PyObject *)CPyPoint::create(dst);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, convertToUI)
	{
		PyObject* pt = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&pt) )
			Py_RETURN_NONE;
		if(!pt || !PyObject_TypeCheck(pt, CPyClassBase::GetTypeObject<CPyPoint>()))
			Py_RETURN_NONE;
		CPyPoint *point = (CPyPoint *)pt;
		cocos2d::CCPoint dst = cocos2d::CCDirector::sharedDirector()->convertToUI(point->getCCObject());
		return (PyObject *)CPyPoint::create(dst);
	}
	
	PYCLASS_METHOD_IMPL(CPyDirector, pushScene)
	{
		PyObject* scene = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&scene) )
		{
			Py_RETURN_NONE;
		}
		if(!scene)
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(scene, CPyClassBase::GetTypeObject<CPyScene>()))
			Py_RETURN_NONE;
		CPyScene *pyScene = (CPyScene *)scene;
		cocos2d::CCScene *pScene = dynamic_cast<cocos2d::CCScene *>(pyScene->getCCObject());
		if(pScene)
			cocos2d::CCDirector::sharedDirector()->pushScene(pScene);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, popScene)
	{
		cocos2d::CCDirector::sharedDirector()->popScene();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, popToRootScene)
	{
		cocos2d::CCDirector::sharedDirector()->popToRootScene();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, replaceScene)
	{
		PyObject* scene = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&scene) )
		{
			Py_RETURN_NONE;
		}
		if(!scene)
			Py_RETURN_NONE;
		
		if(!PyObject_TypeCheck(scene, CPyClassBase::GetTypeObject<CPyScene>()))
			Py_RETURN_NONE;
		CPyScene *pyScene = (CPyScene *)scene;
		cocos2d::CCScene *pScene = dynamic_cast<cocos2d::CCScene *>(pyScene->getCCObject());
		if(pScene)
			cocos2d::CCDirector::sharedDirector()->replaceScene(pScene);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, drawScene)
	{
		cocos2d::CCDirector::sharedDirector()->drawScene();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, purgeCachedData)
	{
		cocos2d::CCDirector::sharedDirector()->purgeCachedData();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, end)
	{
		cocos2d::CCDirector::sharedDirector()->end();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, pause)
	{
		cocos2d::CCDirector::sharedDirector()->pause();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, resume)
	{
		cocos2d::CCDirector::sharedDirector()->resume();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setGLDefaultValues)
	{
		cocos2d::CCDirector::sharedDirector()->setGLDefaultValues();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setAlphaBlending)
	{
		PyObject* pb = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&pb) )
			Py_RETURN_NONE;
		cocos2d::CCDirector::sharedDirector()->setAlphaBlending(pb == Py_True);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setDepthTest)
	{
		PyObject* pb = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&pb) )
			Py_RETURN_NONE;
		cocos2d::CCDirector::sharedDirector()->setDepthTest(pb == Py_True);
		Py_RETURN_NONE;
	}

	//////////////////////////////////////////////////////
	
	PYCLASS_METHOD_IMPL(CPyDirector, getRunningScene)
	{
		cocos2d::CCScene *pScene = cocos2d::CCDirector::sharedDirector()->getRunningScene();
		if(!pScene)
			Py_RETURN_NONE;
		IWrapper *wrap = dynamic_cast<IWrapper *>(pScene);
		if(wrap)
		{
			if(wrap->GetPythonObject())
			{
				Py_XINCREF(wrap->GetPythonObject());
				return wrap->GetPythonObject();
			}
			return (PyObject *)CPyCCObject::create_object(wrap->GetPythonType(), pScene);
		}
		return (PyObject *)CPyCCObject::create<CPyScene>(pScene);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getSecondsPerFrame)
	{
		float v = cocos2d::CCDirector::sharedDirector()->getSecondsPerFrame();
		return Py_BuildValue("f", v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, isPaused)
	{
		bool v = cocos2d::CCDirector::sharedDirector()->isPaused();
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getTotalFrames)
	{
		unsigned int v = cocos2d::CCDirector::sharedDirector()->getTotalFrames();
		return Py_BuildValue("I", v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, isSendCleanupToScene)
	{
		bool v = cocos2d::CCDirector::sharedDirector()->isSendCleanupToScene();
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getWinSize)
	{
		cocos2d::CCSize size = cocos2d::CCDirector::sharedDirector()->getWinSize();
		return (PyObject *)CPySize::create(size);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getWinSizeInPixels)
	{
		cocos2d::CCSize size = cocos2d::CCDirector::sharedDirector()->getWinSizeInPixels();
		return (PyObject *)CPySize::create(size);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getVisibleSize)
	{
		cocos2d::CCSize size = cocos2d::CCDirector::sharedDirector()->getVisibleSize();
		return (PyObject *)CPySize::create(size);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getVisibleOrigin)
	{
		cocos2d::CCPoint pt = cocos2d::CCDirector::sharedDirector()->getVisibleOrigin();
		return (PyObject *)CPyPoint::create(pt);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getZEye)
	{
		float v = cocos2d::CCDirector::sharedDirector()->getZEye();
		return Py_BuildValue("f", v);
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, getDeltaTime)
	{
		float v = cocos2d::CCDirector::sharedDirector()->getDeltaTime();
		return Py_BuildValue("f", v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getAnimationInterval)
	{
		double v = cocos2d::CCDirector::sharedDirector()->getAnimationInterval();
		return Py_BuildValue("d", v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setAnimationInterval)
	{
		double v = 0;
		if( !PyArg_ParseTuple(pyArgs,"d",&v) )
			Py_RETURN_NONE;
		cocos2d::CCDirector::sharedDirector()->setAnimationInterval(v);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, isDisplayStats)
	{
		bool v = cocos2d::CCDirector::sharedDirector()->isDisplayStats();
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setDisplayStats)
	{
		PyObject* pb = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&pb) )
			Py_RETURN_NONE;
		cocos2d::CCDirector::sharedDirector()->setDisplayStats(pb == Py_True);
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, getOpenGLView)
	{
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, setOpenGLView)
	{
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPyDirector, isNextDeltaTimeZero)
	{
		bool v = cocos2d::CCDirector::sharedDirector()->isNextDeltaTimeZero();
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setNextDeltaTimeZero)
	{
		PyObject* pb = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&pb) )
			Py_RETURN_NONE;
		cocos2d::CCDirector::sharedDirector()->setNextDeltaTimeZero(pb == Py_True);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getProjection)
	{
		cocos2d::ccDirectorProjection v = cocos2d::CCDirector::sharedDirector()->getProjection();
		return Py_BuildValue("I", static_cast<unsigned int>(v));
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setProjection)
	{
		unsigned int v = 0;
		if( !PyArg_ParseTuple(pyArgs,"I",&v) )
			Py_RETURN_NONE;
		cocos2d::CCDirector::sharedDirector()->setProjection(static_cast<cocos2d::ccDirectorProjection>(v));
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPyDirector, getNotificationNode)
	{
		cocos2d::CCNode *p = cocos2d::CCDirector::sharedDirector()->getRunningScene();
		if(!p)
			Py_RETURN_NONE;
		return (PyObject *)CPyCCObject::create<CPyNode>(p);
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setNotificationNode)
	{
		PyObject* py = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&py) )
		{
			Py_RETURN_NONE;
		}
		if(!py)
			Py_RETURN_NONE;
		
		CPyCCObject *p = (CPyCCObject *)py;
		cocos2d::CCNode *pNode = dynamic_cast<cocos2d::CCNode *>(p->getCCObject());
		if(pNode)
			cocos2d::CCDirector::sharedDirector()->setNotificationNode(pNode);
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, getDelegate)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, setDelegate)
	{
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPyDirector, getContentScaleFactor)
	{
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, setContentScaleFactor)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getScheduler)			
	{
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, setScheduler)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getActionManager)			
	{
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, setActionManager)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getTouchDispatcher)			
	{
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, setTouchDispatcher)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getKeypadDispatcher)			
	{
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, setKeypadDispatcher)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, getAccelerometer)			
	{
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyDirector, setAccelerometer)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, addStandardDelegate)
	{
		PyObject* pyO = NULL;
		int proi = 0;
		if( !PyArg_ParseTuple(pyArgs,"Oi",&pyO, &proi) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyO, CPyClassBase::GetTypeObject<CPyCCObject>()))
			Py_RETURN_NONE;
		CPyCCObject *td = (CPyCCObject *)pyO;
		CCTouchDelegate *tdg = dynamic_cast<CCTouchDelegate *>(td->getCCObject());
		cocos2d::CCTouchDispatcher *disp = CCDirector::sharedDirector()->getTouchDispatcher();
		if(disp && tdg)
			disp->addStandardDelegate(tdg, proi);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, addTargetedDelegate)
	{
		PyObject* pyO = NULL;
		int proi = 0;
		PyObject* pyB = NULL;
		if( !PyArg_ParseTuple(pyArgs,"OiO",&pyO, &proi, &pyB) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyO, CPyClassBase::GetTypeObject<CPyCCObject>()))
			Py_RETURN_NONE;
		CPyCCObject *td = (CPyCCObject *)pyO;
		bool bSwallowsTouches = pyB == Py_True;
		CCTouchDelegate *tdg = dynamic_cast<CCTouchDelegate *>(td->getCCObject());
		cocos2d::CCTouchDispatcher *disp = CCDirector::sharedDirector()->getTouchDispatcher();
		if(disp && tdg)
			disp->addTargetedDelegate(tdg, proi, bSwallowsTouches);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyDirector, removeDelegate)
	{
		PyObject* pyO = NULL;
		if( !PyArg_ParseTuple(pyArgs,"O",&pyO) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyO, CPyClassBase::GetTypeObject<CPyCCObject>()))
			Py_RETURN_NONE;
		CPyCCObject *td = (CPyCCObject *)pyO;
		CCTouchDelegate *tdg = dynamic_cast<CCTouchDelegate *>(td->getCCObject());
		cocos2d::CCTouchDispatcher *disp = CCDirector::sharedDirector()->getTouchDispatcher();
		if(disp && tdg)
			disp->removeDelegate(tdg);
		Py_RETURN_NONE;
	}

NS_CCPY_END

#endif